home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / BUS / TMCM Software and Labs.sit / Software for TMCM 7_95 / Files For Lab 8 / EchoNums and Background Process < prev    next >
Text File  |  1995-07-13  |  5KB  |  197 lines

  1. ; This program illustrates interrupt handling in xComputer.
  2. ; To use this program, you must turn on the "Use I/O Services"
  3. ; option in the "Options" menu.
  4.  
  5. ; The program performs the same computation as the sample
  6. ; program EchoNums, but it does the computaton as an
  7. ; interrupt handler.  When there is no user input to be
  8. ; processed, the computer executes a "background task".
  9. ; In the EchoNums program, the computer wasted a lot of
  10. ; time just waiting for user input.  Here, it devotes
  11. ; this otherwise "idle" time to a useful computation.
  12. ; (The background computation in this case is computng
  13. ; powers of three, but you don't need to worry about
  14. ; the details.)
  15.  
  16.  
  17.            lod-c 0        ; "Num" holds the number being input.
  18.            sto num        ; Start with Num = 0, before anything is typed.
  19.  
  20.            inh get_ch     ; Set up "get_ch" as an interrupt handler.
  21.                           ;   The program jumps to this location asynchronously
  22.                           ;   When the user types a character.
  23.  
  24.            jmp backgrnd   ; Start the "background process" which will run
  25.                           ;   except when user input is being processed.
  26.  
  27. get_ch:    gtc            ; Begin interrupt handler. Get the next char from input.
  28.            jmz get_ch
  29.  
  30.            sto ch         ; Save the non-zero char in "ch" for processing.
  31.  
  32.            lod ch         ; Compare the input char to ".".  If it is ".",
  33.            sub-c '.       ;     then jump to "end_num", where the num will
  34.            jmz end_num    ;     be output.
  35.  
  36.            lod-c '9       ; Check if ch if bigger than "9".
  37.            sub ch 
  38.            jmn done       ; If so, jump to "return", and end interrupt processing.
  39.  
  40.            lod ch         ; Check if ch is less than "0". 
  41.            sub-c '0  
  42.            jmn done       ; If so, jump to "return", and end interrupt processing.
  43.  
  44.            sto digit      ; Save input digit into location "digit".
  45.  
  46.            lod num        ; Set num = 10*num + digit.
  47.            shl 
  48.            sto num 
  49.            shl 
  50.            shl
  51.            add num  
  52.            add digit 
  53.            sto num  
  54.            rti            ; And end the interrupt.
  55.  
  56. end_num:   lod num        ; The program jumps here when the user types ".".
  57.            pti            ;    Get the value of num and write it to output
  58.                           ;    as an integer.
  59.  
  60.            lod-c 0        ; Start over with num = 0.
  61.            sto num
  62.  
  63. done:      rti            ; End the interrupt handler's operations, return
  64.                           ; control to the "background process".
  65.  
  66. ch:        data           ; Location to hold character input by user.
  67.  
  68. digit:     data           ; Location to hold the single-digit number
  69.                           ;   represented by an input character in the
  70.                           ;   range "0" through "9".
  71.  
  72. num:       data           ; Location to hold the (multi-digit) number
  73.                           ;   begin typed in by the user.
  74.  
  75. ; -------------------------------------------------------------------
  76.  
  77. @200   ; Load the following instructions starting at location 200
  78.  
  79. backgrnd:           ; The "background process" starts here.
  80.                     ; (It computes powers of 3, to as many binary
  81.                     ; digits as it has time to compute.  The number
  82.                     ; begin computed is stored in a data area at
  83.                     ; location 1000.  A second data area at
  84.                     ; location 600 is used for "scratch work".
  85.                     ; You do NOT have to understand this program,
  86.                     ; no commenting is provided.  It just gives
  87.                     ; the computer something complicated and 
  88.                     ; marginally interesting to do.)
  89.  
  90.        lod-c 3
  91.        sto N1
  92.        lod-c 1
  93.        sto ct1
  94.  
  95. copy:  lod ct1
  96.        sto ct2
  97.        sto ct
  98.        lod-c N1
  99.        sto src
  100.        lod-c N2
  101.        sto dest
  102. c1:    lod-i src
  103.        sto-i dest
  104.        lod ct
  105.        dec
  106.        jmz sum
  107.        sto ct
  108.        lod src
  109.        dec
  110.        sto src
  111.        lod dest
  112.        dec
  113.        sto dest
  114.        jmp c1
  115.  
  116. sum:   lod ct2
  117.        sto ct
  118.        lod-c N2
  119.        sto src
  120.        lod-c N1
  121.        sto dest
  122.        lod-c 0
  123.        sto carryQ
  124. s1:    lod-i dest
  125.        add-i src
  126.        sto-i dest
  127.        jmf cr1
  128. s2:    lod-i dest
  129.        add-i src
  130.        sto-i dest
  131.        jmf cr2
  132. s3:    lod ct
  133.        dec
  134.        jmz copy
  135.        sto ct
  136.        lod src
  137.        dec
  138.        sto src
  139.        lod dest
  140.        dec
  141.        sto dest
  142.        jmp s1
  143.  
  144. cr1:   lod-c s2
  145.        sto return
  146.        jmp add1
  147.  
  148. cr2:   lod-c s3
  149.        sto return
  150.        jmp add1
  151.  
  152. add1:  lod ct
  153.        sto aCt
  154.        lod dest
  155.        sto aDest
  156. a1:    lod aDest
  157.        dec
  158.        sto aDest
  159.        lod aCt
  160.        dec
  161.        sto aCt
  162.        jmz advnc
  163.        lod-i aDest
  164.        add-c 1
  165.        sto-i aDest
  166.        jmf a1
  167.        jmp-i return
  168. advnc: lod carryQ
  169.        jmz adv1
  170.        lod-i aDest
  171.        add-c 1
  172.        sto-i aDest
  173.        jmp-i return
  174. adv1:  lod ct1
  175.        inc
  176.        sto ct1
  177.        lod-c 1
  178.        sto-i aDest
  179.        lod-c 1
  180.        sto carryQ
  181.        jmp-i return
  182.  
  183. return:data
  184. ct1:   data
  185. ct2:   data
  186. ct:    data
  187. src:   data
  188. dest:  data
  189. aCt:   data
  190. aDest: data
  191. carryQ:data
  192.  
  193. @700
  194. N1: data
  195. @1000
  196. N2: data
  197.